﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyHttp.validator
{
    public class IntegerValidator
    {
        public static Int32? validate(String str, Int32? maximum, Int32? minimum) {
            try {
                int number = Int32.Parse(str);
                if (maximum.HasValue && number > maximum.Value ||
                    minimum.HasValue && number < minimum.Value)
                {
                    return null;
                }
                return number;
            } catch (System.Exception ex) {
                
            }
            return null;
        }

        public static long? validateLong(String str, Int64? maximum, Int64? minimum) {
            try {
                long number = Int64.Parse(str);
                if (maximum.HasValue && number > maximum.Value ||
                    minimum.HasValue && number < minimum.Value)
                {
                    return null;
                }
                return number;
            } catch (System.Exception ex) {
                
            }
            return null;
        }
    }
}
